<template>
	<Modal v-model="modal" class="modal-list-text" title="选择文本">
		<Row>
            <ChoiseTable ref="table" :url="table.url" :async="false" :header="table.header" :currentCallBack="choise" ></ChoiseTable>
        </Row>
        <div slot="footer">
            <Button type="primary" :disabled="disabled" @click="ok">确定</Button>
            <Button @click="cancel">取消</Button>
        </div>
	</Modal>
</template>
<script>
	import {Row,Col,Modal,Page,Button} from 'view-design';

	import ChoiseTable  from 'admin/components/common/table/choise';

	export default {
		props :{
            callback :{
            	type : Function,
            }
        },
		components:{
			Modal,
			Row,
            'ICol':Col,
            Page,
            ChoiseTable,
            Button,
		},
		data () {
			return {
				modal: false,
                table:{
            		url : '/wechat/manager/material/view/text/list',
            		header: []
            	},
            	disabled: true,
                choise_id : 0,
			}
		},
		methods: {
			getData(){
				this.$refs.table.init({page:1,length:10});
			},
			//分页获取
        	pageChange(page){
                this.getData();
            },
            //确定
            ok(){
            	this.modal = false;
            	this.callback(this.choise_id);
            },
            //取消
            cancel(){
            	this.modal = false;
            },
            //选择
            choise(row){
            	this.disabled = false;
                this.choise_id = row.id;
            }
		},
		created:function(){
        	this.table.header =  [
                {
			        title: '文本名',
			        key: 'name'
			    },
			    {
			        title: '更新时间',
			        key: 'updated_at'
			    }
            ];
        },
        watch:{
        	modal(newVue,oldVue){
                this.disabled = true;
        		if(newVue){
        			this.getData();
        		}
        	}
        }
	}
</script>